Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

peek-stream

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

peek-stream

Transform stream that lets you peek the first line before deciding how to parse it

  • 1.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.9M
increased by5.5%
Maintainers
1
Weekly downloads
 
Created

What is peek-stream?

The peek-stream npm package is a Node.js module that allows you to peek at the beginning of a stream to determine its content before deciding how to process it. This can be useful when you need to inspect the start of a stream to make decisions based on its initial data without consuming the stream entirely.

What are peek-stream's main functionalities?

Peeking at stream content

This code sample demonstrates how to use peek-stream to inspect the first 10 bytes of a file stream. If the file starts with 'PNG', it swaps the stream with a new PngDecoderStream; otherwise, it continues with the original stream.

const peek = require('peek-stream');
const fs = require('fs');

const stream = fs.createReadStream('example.txt');
const peekStream = peek({ maxBuffer: 10 }, function(data, swap) {
  // data is the first 10 bytes of the stream
  if (data.toString().startsWith('PNG')) {
    swap(null, new PngDecoderStream());
  } else {
    swap();
  }
});

stream.pipe(peekStream).pipe(process.stdout);

Other packages similar to peek-stream

Keywords

FAQs

Package last updated on 21 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc